/*
 * This is the Chat Pane Class, used in the Main Window to display messages
 */
package gui;

import java.io.IOException;
import java.util.Observable;
import java.util.Observer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JEditorPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;

/**
 *
 * @author mabille
 */
public class ChatPane extends JEditorPane implements Observer {

    private HTMLEditorKit kit;
    private HTMLDocument doc;

    /**
     * The constructor of the ChatPane
     */
    public ChatPane() {
        kit = new HTMLEditorKit();
        doc = new HTMLDocument();
        this.setEditorKit(kit);
        this.setDocument(doc);
    }

    /**
     * The observer method
     *
     * @param o The observable
     * @param arg The object to observe
     */
    @Override
    public void update(Observable o, Object arg) {
        try {
            kit.insertHTML(doc, doc.getLength(), (String) arg, 0, 0, null);
        } catch (BadLocationException ex) {
            Logger.getLogger(ChatPane.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(ChatPane.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}
